package com.xiong.lambda;

import com.xiong.lambda.ext.ForEachCallback;
import com.xiong.lambda.ext.FilterCallback;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class LambdaModel {

    private List<Map<String,Object>> mapList;

    public LambdaModel forEach(ForEachCallback callBack){
        for (int i = 0; i < mapList.size() ; i++) {
            Map<String,Object> map=mapList.get(i);
            callBack.handlerObj(map);
        }
        return this;
    }

    public LambdaModel filter(FilterCallback filterCallback){
        List<Map<String,Object>> arrs=new ArrayList<>();
        for (int i = 0; i < mapList.size()  ; i++) {
            Map<String,Object> map=mapList.get(i);
            boolean flag=filterCallback.dealFilter(map);
            if(flag){
                arrs.add(map);
            }
        }
        this.mapList=arrs;
        return this;
    }

    public List<Map<String,Object>> getMapList(){
        return this.mapList;
    }

    public LambdaModel(List<Map<String, Object>> mapList) {
        this.mapList = mapList;
    }
}
